package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Slf4j
@Api(tags = "菜品管理")
public class DishController {
    @Autowired
    private DishService dishService;

    @GetMapping("/page")
    public Result page(DishPageQueryDTO dishPageQueryDTO){
        PageResult p = dishService.page(dishPageQueryDTO);
        return Result.success(p);
    }

    @PostMapping("/status/{status}")
    public Result changeStatus(@PathVariable Integer status,Long id) {
        dishService.changeStatus(status,id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable Long id){
        DishVO dishVO = dishService.findById(id);
        return Result.success(dishVO);
    }

    @GetMapping("/list")
    public Result findByCategoryId(Long categoryId){
        List<Dish> dish = dishService.findByCategoryId(categoryId);
        return Result.success(dish);
    }

    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Long> ids){
        dishService.deleteByIds(ids);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody DishDTO dishDTO){
        dishService.add(dishDTO);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody DishDTO dishDTO){
        dishService.update(dishDTO);
        return Result.success();
    }
}
